<%@page import="server.FarmerHandler"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SEED FINDER</title>
<link href="2340main.css" rel="stylesheet" type="text/css" />

</head>

<body>
<div id="box">
<div id="top"><h1>Seed Swap</h1></div>

<div id="main">
<div id="left"><br />
    <%
    FarmerHandler fh = new FarmerHandler();
                      String login = request.getParameter("login");
                      if (login != null) {
                         out.println("<font color=red>");
                         if ("bad".equals(login)) {
                             out.println("invalid password");
                         } else if ("format".equals(login)) {
                             out.println("invalid email format");
                         }  else if("noexist".equals(login)){
                             out.println("user does not exist");
                         } else if("lockedout".equals(login)){
                             out.println("account has been locked out");
                         }
                         out.println("</font>");
                       } 
        Cookie cookies[] = request.getCookies();
        String logout = request.getParameter("logout");
        if(logout!=null){
            if("true".equals(logout)){
                if (cookies.length > 0) {
            for (Cookie cookie : cookies) {
                cookie.setMaxAge(0);
                response.addCookie(cookie);
                               }
                       }
            }
        }

            
        
        if(cookies != null){
            String use="";
            if(cookies.length > 0){
                for(Cookie cookie : cookies){
                    if(cookie.getName().equals("user")){
                        use = cookie.getValue();
                    }
                }
            }
        if (!"".equals(use) && logout==null) {
            for (Cookie cookie : cookies) {
             if (cookie.getName().equals("user")) {
                out.println("<h3>Hello " + cookie.getValue() + " welcome back </h3>");
                out.println("<a href='index.jsp'>Main</a><br />");
                out.println("<a href='newseed.jsp'>Create</a><br />");
                out.println("<a href='search.jsp'>Search</a><br />");
                if(fh.getFarmer(cookie.getValue()).getIsAdmin()){
                out.println("<a href='admin.jsp'>Admin</a><br />");
                               }
                out.println("<form action='Logout'><input type='submit' Value='logout'></form>");
             }
            }
        } else {
          out.println("<form action='UserServlet'> Username: <br /><input type='text' name='name' /><br />Password: <br /><input type='password' name='pwd' /><br /><input type='submit' value='submit'></form>");
          out.println("<br /><a href='register.jsp'>Register here</a>");
          }}
        else{
            out.println("<form action='UserServlet'> Username: <br /><input type='text' name='name' /><br />Password: <br /><input type='text' name='pwd' /><br /><input type='submit' value='submit'></form>");
            out.println("<br /><a href='register.jsp'>Register here</a>");      	
        }
 
    %>
</div><div id="right">
    